package jdly.water.api.service.cost;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import jdly.water.api.common.service.R;
import jdly.water.api.dao.common.BaseDAO;
import jdly.water.api.dao.cost.AccountDao;
import jdly.water.api.dao.cost.BalanceDao;
import jdly.water.api.dao.cost.DetailDao;
import jdly.water.api.dao.cost.PayDao;
import jdly.water.api.model.PageModel;
import jdly.water.entity.cost.BalanceRecord;
import jdly.water.entity.cost.PayRecord;
import jdly.water.entity.cost.UserAccount;
import jdly.water.entity.cost.UserAccountDetail;

@Service
public class CostService {

	@Autowired
	private BaseDAO<UserAccount, String> baseDao;

	@Autowired
	private PayDao payDao;

	@Autowired
	private BalanceDao balanceDao;

	@Autowired
	private AccountDao accountDao;
	
	@Autowired
	private DetailDao detailDao;

	public R userlist(LinkedHashMap<String, Object> param, Map<String, String> sortmap, PageModel page) {
		R r = R.ok();
		List<UserAccount> datalist = baseDao.findByMoreFiledpages("UserAccount", param, page.getPage(), page.getLimit(),
				sortmap);
		r.put("datalist", datalist);
		return r;
	}

	public R userinfo(String id) {
		R r = R.ok();
		try {
			UserAccount account = accountDao.findOne(id);
			r.put("account", account);
		} catch (Exception e) {
			r = R.error();
			e.printStackTrace();
		}
		return r;
	}

	public R balancelist(String id) {

		R r = R.ok();
		try {
			List<BalanceRecord> list = balanceDao.list(id);
			r.put("datalist", list);
		} catch (Exception e) {
			r = R.error();
			e.printStackTrace();
		}
		return r;
	}

	public R paylist(String id) {

		R r = R.ok();
		try {
			List<PayRecord> list = payDao.list(id);
			r.put("datalist", list);
		} catch (Exception e) {
			r = R.error();
			e.printStackTrace();
		}
		return r;
	}
//
//	public R detailist(LinkedHashMap<String, Object> param, PageModel page) {
//		R r = R.ok();
//		try {
//			List<UserAccountDetail> list = detailDao.findByMoreFiledpages("UserAccountDetail", param, page);
//			r.put("datalist", list);
//		} catch (Exception e) {
//			e.printStackTrace();
//			r.error();
//		}
//		return r;
//	}
	
	public R detaillist(String id) {
		R r = R.ok();
		try {
			List<UserAccountDetail> list = detailDao.list(id);
			r.put("datalist", list);
		} catch (Exception e) {
			r = R.error();
			e.printStackTrace();
		}
		return r;
	}
}
